/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 刘远望
 * Date: 2025-05-01
 * Time: 19:11
 */
public enum TestEnum {
    RED(0, "red"), WHITE(1, "white"), GREEN(2, "green"), BLACK(3, "black");

    public int ordinal;
    public String color;

    private TestEnum(int ordinal, String color) {
        this.ordinal = ordinal;
        this.color = color;
    }

    public int getOrdinal() {
        return ordinal;
    }

    public static void main(String[] args) {
        TestEnum testEnum = TestEnum.RED;
        System.out.println(testEnum.getOrdinal());

    }

    public static void main2(String[] args) {
        TestEnum[] testEnums = TestEnum.values();
        for (int i = 0; i < testEnums.length; i++) {
            System.out.println(testEnums[i] + " " + testEnums[i].ordinal());
        }

        TestEnum testEnum = TestEnum.valueOf("WHITE");
        System.out.println(testEnum);

        System.out.println(WHITE.compareTo(BLACK));//比较ordinal
    }

    public static void main1(String[] args) {
        TestEnum testEnum = RED;
        switch (testEnum) {
            case RED:
                System.out.println("red");
                break;
            case WHITE:
                System.out.println("white");
                break;
            case GREEN:
                System.out.println("green");
                break;
            case BLACK:
                System.out.println("balck");
                break;
            default:
                System.out.println("错误");
                break;
        }
    }
}
